#coding = utf8

import jaydebeapi

url = 'jdbc:hive2://mynode1:10000/default'
# 连接HIve用户名、密码
user = ''
password = ''
# 连接Hive使用的驱动
driver = 'org.apache.hive.jdbc.HiveDriver'
# 准备连接Hive的依赖Jar包
jarFile = [
    'D:\\python_conn_hive\\hive-jdbc-1.2.1.jar',
    'D:\\python_conn_hive\\hive-exec-1.2.1.jar',
    'D:\\python_conn_hive\\hive-metastore-1.2.1.jar',
    'D:\\python_conn_hive\\hive-service-1.2.1.jar',
    'D:\\python_conn_hive\\hadoop-common-2.7.4.jar',
    'D:\\python_conn_hive\\libfb303-0.9.2.jar',
    'D:\\python_conn_hive\\commons-logging-1.2.jar',
    'D:\\python_conn_hive\\slf4j-api-1.7.25.jar',
    'D:\\python_conn_hive\\httpclient-4.5.6.jar',
    'D:\\python_conn_hive\\httpcore-4.4.10.jar',
    'D:\\python_conn_hive\\slf4j-simple-1.7.12.jar']

#准备sql语句
sqlStr = 'select * from person'

#创建Hive连接
conn = jaydebeapi.connect(driver, url, [user, password], jarFile)

#创建执行sql对象
curs = conn.cursor()
#执行sql
curs.execute(sqlStr)

#获取结果
result = curs.fetchall()
print(result)

#关闭对象
curs.close()
conn.close()